#!/bin/bash

# 配置Docker镜像加速器（中国大陆用户）

echo "======================================"
echo "配置Docker镜像加速器"
echo "======================================"

# 创建或更新daemon.json
echo "正在配置Docker镜像源..."
echo "newhand" | sudo -S mkdir -p /etc/docker

echo "newhand" | sudo -S tee /etc/docker/daemon.json > /dev/null << 'EOF'
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://mirror.ccs.tencentyun.com",
    "https://registry.docker-cn.com",
    "https://hub-mirror.c.163.com"
  ]
}
EOF

# 重启Docker服务
echo ""
echo "重启Docker服务..."
echo "newhand" | sudo -S systemctl daemon-reload
echo "newhand" | sudo -S systemctl restart docker

echo ""
echo "======================================"
echo "Docker镜像加速器配置完成！"
echo "======================================"
echo ""
echo "可以使用以下命令验证配置："
echo "sudo docker info | grep -A 5 'Registry Mirrors'"